//
//  TraderAddManOfStoreCell.m
//  WGFGlobalHouses
//
//  Created by zhouhui on 15/4/19.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//  某个门店下的经纪人cell

#import "TraderManOfStoreCell.h"
#define SCALE UIScreenWidth/320.0
@interface TraderManOfStoreCell()

@property (weak, nonatomic) IBOutlet UIView *mainView;
- (IBAction)clickBackView:(id)sender;
@property(nonatomic,assign) NSInteger  flag;
@property(nonatomic,assign) NSInteger row;
//勾选图片
@property (weak, nonatomic) IBOutlet UIImageView *markImg;
//已禁用
@property (weak, nonatomic) IBOutlet UILabel *forbiddenLab;
@property (weak, nonatomic) IBOutlet UIControl *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;


@end


@implementation TraderManOfStoreCell

+(instancetype)cellWithTableView:(UITableView *)tableView withRow:(NSInteger)row;
{
    static NSString *ID = @"traderManOfStore";
    TraderManOfStoreCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"TraderManOfStoreCell" owner:nil options:nil]lastObject];
    }
    
    cell.row = row;
    return cell;
}

-(void)layoutSubviews
{
//    [super layoutSubviews];
//    self.view1.frame = CGRectMake(30*SCALE, 0, UIScreenWidth, 44);
//    self.view2.frame = CGRectMake(350*SCALE, 0, 130*SCALE, 44);
//    self.mainView.frame = CGRectMake(-30*SCALE, 0, 480*SCALE, 44);
}

- (void)awakeFromNib
{
    self.flag = 0;
    self.forbiddenLab.hidden = YES;
    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeCell:)];
    swipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [self addGestureRecognizer:swipe];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moveTickBtnToSee) name:@"moveTickBtnToSee" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moveTickBtnToNotSee) name:@"moveTickBtnToNotSee" object:nil];
    
    //把打勾图片都打勾
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(respondToSelectAllMiddleMan:) name:@"selectAllMiddleMan" object:nil];
    //已禁用
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(respondToForbiddenMiddleMan:) name:@"forbiddenMiddleMan" object:nil];

}
-(void)respondToForbiddenMiddleMan:(NSNotification *)notify
{
    NSNumber *tagNum = [notify object];
    NSInteger tag = [tagNum  integerValue];
    
    if (tag == 2)
    {
        self.forbiddenLab.hidden = YES;
    }else
    {
        self.forbiddenLab.hidden = NO;
    }
}
-(void)respondToSelectAllMiddleMan:(NSNotification *)notify
{
    NSNumber *imgNum = [notify object];
    NSInteger tag = [imgNum integerValue];
    if (tag == 1)
    {
        [self selectCell];
    }else
    {
        [self deSelectCell];
    }
    
}
#pragma mark 让cell打勾
-(void)selectCell
{
    self.markImg.image = [UIImage imageNamed:@"fuxuan_birder_si"];
    self.markImg.tag = 1;
}
#pragma mark cell不打勾
-(void)deSelectCell
{
    self.markImg.image = [UIImage imageNamed:@"fuxuan_birder"];
    self.markImg.tag = 0;
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


-(void)moveTickBtnToSee
{
    self.flag = 1;
    self.mainView.frame = CGRectMake(0, 0,480*SCALE, 44);
}
-(void)moveTickBtnToNotSee
{
    
    self.flag = 0;
    [self clickBackView:nil];
    
    
}


#pragma mark 处理滑动事件
-(void)swipeCell:(UISwipeGestureRecognizer *)gesture
{
    if (self.flag == 0)
    {
        self.mainView.frame = CGRectMake(-157*SCALE, 0,480*SCALE, 44);
    }
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)clickBackView:(id)sender {
    if (self.flag == 0)
    {
        self.mainView.frame = CGRectMake(-30*SCALE, 0,480*SCALE, 44);
//        self.flag = 1;
    }
    
    
}
@end
